﻿<?php
ini_set('date.timezone','Asia/Shanghai');
ini_set('memory_limit','100000M');

include 'simple_html_dom.php';
include 'config_catchjifeng.php';

define('APPS_NUM',2405);
define('GAMES_NUM',977);

define('DBPAS',"coolchuan2012");
//define('DBPAS',"123456");

$link = mysql_connect("localhost","root",DBPAS); 
mysql_select_db("catchappdataall", $link);
mysql_query('SET NAMES UTF8');


define('ONCECATCHCOUNT',10);
define('ONCECOMMENTCATCHCOUNT',10);

define('WEBURLHEADER','http://apk.gfan.com/Product/App');
define('WEBURLFOOTER','.html');


define('LOGPATHHEADER','/var/www/catchjiankongdata/');
//define('LOGPATHHEADER','');

//http://3g.gfan.com/data/index.php?/lists/ajaxpage/1/3/app/3/?callback=jQuery16105541677612345666_1373352697619&_=1373352755035
//http://3g.gfan.com/data/index.php?/lists/ajaxpage/1/1/app/3/?callback=jQuery161008269634004682302_1373352805380&_=1373352805449
define('LOGFORSUCCESS',0);

//getinfoandrank();

getcomment();


function getinfoandrank()
{
	//获取已存在app基础数据
	
	//应用分类
	$apptype_arr = getapptypelist();
	foreach ($apptype_arr as $apptype)
	{
		//每一类的url
		$apps_url_app_type_list = $apptype['url'];
		decodeurlandgetdata($apptype['id'],"soft",$apps_url_app_type_list);
	}
	//应用总榜
	decodeurlandgetdata(101,"soft","http://3g.gfan.com/data/index.php?/lists/ajaxrank/app/");
	
	//游戏分类
	$gametype_arr = getgametypelist();
	foreach ($gametype_arr as $gametype)
	{
		//每一类的url
		$apps_url_game_type_list = $gametype['url'];
		decodeurlandgetdata($apptype['id'],"game",$apps_url_game_type_list);
	}
	//游戏总榜
	decodeurlandgetdata(102,"game","http://3g.gfan.com/data/index.php?/lists/ajaxrank/game/");
}



function decodeurlandgetdata($catchtype,$appbigtype,$urlheader)
{
	$app_exit_infos = get_exit_appinfo_fromdb();
	$app_exit_versions = get_exit_appversion_fromdb();
	
	$app_today_data = get_today_data();
	$app_today_score = get_today_score();
	
	for($i=1;;)
	{
//		$apps_url_app_all_list = $urlheader.$i."/app/3/";//?callback=catchdatajson
		if($catchtype>100)
		{
			$apps_url_app_all_list = $urlheader.$i."/";
		}
		else 
		{
			if($appbigtype == "soft")
			{
				$apps_url_app_all_list = $urlheader.$i."/app/3/";//?callback=catchdatajson
			}
			else 
			{
				$apps_url_app_all_list = $urlheader.$i."/game/3/";//?callback=catchdatajson
			}
		}
		
		@$json_string = file_get_contents($apps_url_app_all_list);
//		$json_str = json_decode($json_string);var_dump($json_string);die();
        $json_str = $json_string;
		$json_str = substr($json_str, 0, -1);
		$json_str = substr($json_str, 1, strlen($json_str));
		$obj = json_decode($json_str);
		
		$appinfoarr = $obj->list;
		
		if(($obj == "") || ($appinfoarr == "") || (count($appinfoarr)==0))
		{
			break;
		}
		
		
		//有内容，解析
		$rankpos = ($i-1) * ONCECATCHCOUNT;
		$app_info_arr_insertdb_arr = catchinfodata($catchtype,$appbigtype,$rankpos,$appinfoarr);
		
		//写数据库
		foreach ($app_info_arr_insertdb_arr as $app_info_arr_insertdb)
		{
			//判断是否需要更新信息库
			$searchinfoid = searchisexit($app_info_arr_insertdb, $app_exit_infos);
			if($searchinfoid == 0)
			{
				$app_info_arr_insertdb['app_id'] = insert_appinfo_ifnotexit_todb($app_info_arr_insertdb);
				$app_info_arr_insertdb['app_version_id'] = insert_appversion_ifnotexit_todb($app_info_arr_insertdb);
				
				//重新获取存在app信息，因为有了更新
				$app_exit_infos = get_exit_appinfo_fromdb();
				$app_exit_versions = get_exit_appversion_fromdb();
			}
			else 
			{
				$app_info_arr_insertdb['app_id'] = $searchinfoid;
				$searchversionid = searchisexitversion($app_info_arr_insertdb, $app_exit_versions);
				if($searchversionid == 0)
				{
					$app_info_arr_insertdb['app_version_id'] = insert_appversion_ifnotexit_todb($app_info_arr_insertdb);
					
					//重新获取存在app信息，因为有了更新
					$app_exit_versions = get_exit_appversion_fromdb();
				}
				else 
				{
					$app_info_arr_insertdb['app_version_id'] = $searchversionid;
				}
			}
			
			//判断当天没有抓过，再写入
			if(searchisexittodaydata($app_info_arr_insertdb, $app_today_data) == 0)
			{
				update_appinfo_todb($app_info_arr_insertdb);
				$app_today_data = get_today_data();
			}
			if(searchisexittodayscore($app_info_arr_insertdb, $app_today_score) == 0)
			{
				update_appscore_todb($app_info_arr_insertdb);
				$app_today_score = get_today_score();
			}
		}
		
		$i++;
		
	//	结束
	//	if($obj->total < ONCECATCHCOUNT)
	//	{
	//		break;
	//	}
	}
}


function searchisexit($app_infos, $app_exit_info) 
{
	foreach ($app_exit_info as $app_exit) 
	{
		if ($app_infos['packagename'] == $app_exit["AppPackageName"]) 
		{
			return $app_exit['id'];
		}
	}
	return 0;
}

function searchisexitversion($app_infos, $app_exit_version) 
{
	foreach ($app_exit_version as $app_exit) 
	{
		if (($app_infos['app_id'] == $app_exit["app_id"]) && ($app_infos['Versioncode'] == $app_exit["versionCode"]) ) 
		{
			return $app_exit['id'];
		}
	}
	return 0;
}

function searchisexittodaydata($app_infos, $app_today_data) 
{
	foreach ($app_today_data as $app_exit) 
	{
		if (($app_infos['app_id'] == $app_exit["app_id"]) && ($app_infos['AppRanking'] == $app_exit["rank"]) && ($app_infos['AppRankingType'] == $app_exit["ranktype"]))
		{
			return $app_exit['id'];
		}
	}
	return 0;
}
function searchisexittodayscore($app_infos, $app_today_score) 
{
	foreach ($app_today_score as $app_exit)
	{
		if (($app_infos['app_id'] == $app_exit["app_id"]))
		{
			return $app_exit['id'];
		}
	}
	return 0;
}

//排名分类，app大类，app信息
function catchinfodata($catchtype,$appbigtype,$flag,$appinfoarr)
{
	$ranking = $flag ;//* ONCECATCHCOUNT;
	$app_info_insertdb_arr = array();

	foreach($appinfoarr as $appinfo) 
	{
		$ranking++;
		$app_info_insertdb = array();
		$app_info_insertdb['name'] = addslashes($appinfo->name);
		$app_info_insertdb['packagename'] = $appinfo->packagename;
		$app_info_insertdb['AppDownTimes'] = $appinfo->download_count;
		$app_info_insertdb['AppID'] = $appinfo->p_id;
		$app_info_insertdb['Rating'] = $appinfo->rating;
		$app_info_insertdb['AppVersion'] = $appinfo->version_name;
		$app_info_insertdb['Versioncode'] = $appinfo->version_code;
//		$app_info_insertdb['AppBaikeName'] = $appinfo->baike_name;
		$app_info_insertdb['AppLogo'] = $appinfo->icon_url;
		$app_info_insertdb['AppSize'] = $appinfo->app_size;
		
		$app_info_insertdb['AppType'] = "";
//		if($catchtype <= 100)
		{
			$app_info_insertdb['AppType'] = $catchtype;
		}
		$app_info_insertdb['AppBigType'] = $appbigtype;
		$app_info_insertdb['AppRanking'] = $ranking;
		$app_info_insertdb['AppRankingType'] = $catchtype;
		$app_info_insertdb['url'] = WEBURLHEADER.$app_info_insertdb['AppID'].WEBURLFOOTER;
		$app_info_insertdb_arr[] = $app_info_insertdb;
	}
	
	return $app_info_insertdb_arr;
}


function get_exit_appinfo_fromdb()
{
	$link = mysql_connect("localhost","root",DBPAS); 
	$createtime = strtotime(date("Y-m-d H:i:s"));

	$sql = 'select id, app_id, packageName,title from jk_apps_info_jifeng where IsDeleted=0 '; 
	$rs = mysql_query($sql, $link);
	
	$app_exit_info = array();
  	while($row=mysql_fetch_array($rs))        
  	{
  		$app_exit_info_temp = array();
  		$app_exit_info_temp['id'] = $row['id'];
  		$app_exit_info_temp['app_id'] = $row['app_id'];
	  	$app_exit_info_temp['AppPackageName'] = $row['packageName'];
	  	$app_exit_info_temp['AppName'] = $row['title'];
	  	$app_exit_info[] = $app_exit_info_temp;
  	}
	return $app_exit_info;
}

function get_exit_appversion_fromdb()
{
	$link = mysql_connect("localhost","root",DBPAS); 
	$createtime = strtotime(date("Y-m-d H:i:s"));

	$sql = 'select id,app_id,versionName,versionCode from jk_apps_version_jifeng where IsDeleted=0 '; 
	$rs = mysql_query($sql, $link);
	
	$app_exit_version = array();
  	while($row=mysql_fetch_array($rs))        
  	{
  		$app_exit_version_temp = array();
	  	$app_exit_version_temp['id'] = $row['id'];
	  	$app_exit_version_temp['app_id'] = $row['app_id'];
	  	$app_exit_version_temp['versionName'] = $row['versionName'];
	  	$app_exit_version_temp['versionCode'] = $row['versionCode'];
	  	$app_exit_version[] = $app_exit_version_temp;
  	}
	return $app_exit_version;
}

function get_today_data()
{
	$today = date("Y-m-d");
	$link = mysql_connect("localhost","root",DBPAS); 
	
	$sql = 'select id, app_id,rank,ranktype,time from jk_apps_data_mobile_jifeng_'.date('Ym',time()).' where IsDeleted=0 and time="'.$today.'"'; 
	$rs = mysql_query($sql, $link);
	
	$app_exit_info = array();
  	while($row=mysql_fetch_array($rs))        
  	{
  		$app_exit_info_temp = array();
  		$app_exit_info_temp['id'] = $row['id'];
  		$app_exit_info_temp['app_id'] = $row['app_id'];
  		$app_exit_info_temp['rank'] = $row['rank'];
	  	$app_exit_info_temp['ranktype'] = $row['ranktype'];
	  	$app_exit_info_temp['time'] = $row['time'];
	  	$app_exit_info[] = $app_exit_info_temp;
  	}
	return $app_exit_info;
}
function get_today_score()
{
	$link = mysql_connect("localhost","root",DBPAS); 
	$today = date("Y-m-d");

	$sql = 'select id, app_id from jk_apps_score_data_mobile_jifeng_'.date('Ym',time()).' where IsDeleted=0 and time="'.$today.'"'; 
	$rs = mysql_query($sql, $link);
	
	$app_exit_info = array();
  	while($row=mysql_fetch_array($rs))        
  	{
  		$app_exit_info_temp = array();
  		$app_exit_info_temp['id'] = $row['id'];
	  	$app_exit_info_temp['app_id'] = $row['app_id'];
	  	$app_exit_info[] = $app_exit_info_temp;
  	}
	return $app_exit_info;
}

//app基础信息
function insert_appinfo_ifnotexit_todb($app_info)
{
	$link = mysql_connect("localhost","root",DBPAS); 
	$createtime = strtotime(date("Y-m-d H:i:s"));

	$sql = 'insert into jk_apps_info_jifeng (app_id,title,packageName,url,icon,apptype,appbigtype)
	 values ('.$app_info['AppID'].',"'.$app_info['name'].'","'.$app_info['packagename'].'","'.$app_info['url'].'","'.$app_info['AppLogo'].'","'.$app_info['AppType'].'","'.$app_info['AppBigType'].'")'; 

	$rs = mysql_query($sql, $link);
	//echo $sql;die();
	$filename_success = LOGPATHHEADER.'logs/jifeng_info_success.log';
	$filename_fail = LOGPATHHEADER.'logs/jifeng_info_fail.log';
	$filename_db_fail = LOGPATHHEADER.'logs/jifeng_info_db_fail.log';

	try
	{
		if(!$rs)
		{
			//记录错误，二次抓取用
			$info_str = $app_info["name"].$sql."Valid result!\r\n";
			$fh = fopen($filename_db_fail, "a");
			fwrite($fh, $info_str);
			fclose($fh);
			echo $info_str;
		}
		else
		{
			if(LOGFORSUCCESS)
			{
				$info_str = $app_info["name"]."success!\r\n";
				$filename = $filename_success;
				$fh = fopen($filename, "a");
				fwrite($fh, $info_str);
				fclose($fh);
			}
		}
	}
	catch(Exception $e)
	{
		
	}
	
	return mysql_insert_id();
}
//app version信息
function insert_appversion_ifnotexit_todb($app_info)
{
	$link = mysql_connect("localhost","root",DBPAS); 
	$createtime = strtotime(date("Y-m-d H:i:s"));

	$sql = 'insert into jk_apps_version_jifeng (app_id,versionName,versionCode)
	 values ('.$app_info['app_id'].',"'.$app_info['AppVersion'].'","'.$app_info['Versioncode'].'")';

	$rs = mysql_query($sql, $link);
	//echo $sql;die();
	$filename_success = LOGPATHHEADER.'logs/jifeng_info_success.log';
	$filename_fail = LOGPATHHEADER.'logs/jifeng_info_fail.log';
	$filename_db_fail = LOGPATHHEADER.'logs/jifeng_info_db_fail.log';

	try
	{
		if(!$rs)
		{
			//记录错误，二次抓取用
			$info_str = $app_info["name"].$sql."Valid result!\r\n";
			$fh = fopen($filename_db_fail, "a");
			fwrite($fh, $info_str);
			fclose($fh);
			echo $info_str;
		}
		else
		{
			if(LOGFORSUCCESS)
			{
				$info_str = $app_info["name"]."success!\r\n";
				$filename = $filename_success;
				$fh = fopen($filename, "a");
				fwrite($fh, $info_str);
				fclose($fh);
			}
		}
	}
	catch(Exception $e)
	{
		
	}
	return mysql_insert_id();
}
//排名信息
function update_appinfo_todb($app_info)
{
	$link = mysql_connect("localhost","root",DBPAS); 
	$createtime = strtotime(date("Y-m-d H:i:s"));
	
	$today = date("Y-m-d");
	
	$sql = 'insert into jk_apps_data_mobile_jifeng_'.date('Ym',time()).' (app_id,app_version_id,rank,ranktype,time)
	 values ('.$app_info['app_id'].','.$app_info['app_version_id'].','.$app_info['AppRanking'].','.$app_info['AppRankingType'].',"'.$today.'")'; 

//	echo $sql;die();
	$rs = mysql_query($sql, $link);
	
	$filename_success = LOGPATHHEADER.'logs/jifeng_success.log';
	$filename_fail = LOGPATHHEADER.'logs/jifeng_fail.log';
	$filename_db_fail = LOGPATHHEADER.'logs/jifeng_db_fail.log';

	try
	{
		if(!$rs)
		{
			//记录错误，二次抓取用
			$info_str = $app_info["name"].$sql."Valid result!\r\n";
			$fh = fopen($filename_db_fail, "a");
			fwrite($fh, $info_str);
			fclose($fh);
			echo $info_str;
		}
		else
		{
			if(LOGFORSUCCESS)
			{
				$info_str = $app_info["name"]."success!\r\n";
				$filename = $filename_success;
				$fh = fopen($filename, "a");
				fwrite($fh, $info_str);
				fclose($fh);
			}
		}
	}
	catch(Exception $e)
	{
		
	}
}


function getcommentcount($app_id)
{
//	$appnameencode = urlencode($appname);
	$catchcommentcounturl = "http://3g.gfan.com/data/index.php?/detail/ajaxdetail/".$app_id."/";

	
	@$json_string = file_get_contents($catchcommentcounturl);
	$json_str = $json_string;
	
	$json_str = substr($json_str, 0, -1);
	$json_str = substr($json_str, 1, strlen($json_str));
	$obj = json_decode($json_str);
	
	return $obj->comments_count;
}



//监控信息
function update_appscore_todb($app_info)
{
	$link = mysql_connect("localhost","root",DBPAS); 
	$createtime = strtotime(date("Y-m-d H:i:s"));
	
	$today = date("Y-m-d");
	
	if(strstr($app_info['AppDownTimes'],"万"))
	{
		$app_info['AppDownTimes'] = str_replace("万","",$app_info['AppDownTimes']) * 10000;
	}
	if($app_info['Rating'] == "")
	{
		$app_info['Rating'] = 0;
	}
	
	$commentcount = getcommentcount($app_info['AppID']);
	if($commentcount == "")
	{
		$commentcount = 0;
	}
	
	$sql = 'insert into jk_apps_score_data_mobile_jifeng_'.date('Ym',time()).' (app_id,app_version_id,downloads,score,scoretype,comments,time)
	 values ('.$app_info['app_id'].','.$app_info['app_version_id'].','.$app_info['AppDownTimes'].','.$app_info['Rating'].',"",'.$commentcount.',"'.$today.'")'; 

//	echo $sql;die();
	$rs = mysql_query($sql, $link);
	
	$filename_success = LOGPATHHEADER.'logs/jifeng_success.log';
	$filename_fail = LOGPATHHEADER.'logs/jifeng_fail.log';
	$filename_db_fail = LOGPATHHEADER.'logs/jifeng_db_fail.log';

	try
	{
		if(!$rs)
		{
			//记录错误，二次抓取用
			$info_str = $app_info["name"].$sql."Valid result!\r\n";
			$fh = fopen($filename_db_fail, "a");
			fwrite($fh, $info_str);
			fclose($fh);
			echo $info_str;
		}
		else
		{
			if(LOGFORSUCCESS)
			{
				$info_str = $app_info["name"]."success!\r\n";
				$filename = $filename_success;
				$fh = fopen($filename, "a");
				fwrite($fh, $info_str);
				fclose($fh);
			}
		}
	}
	catch(Exception $e)
	{
		
	}
}


//评论
function getcomment()
{
	//获取已存在app基础数据
	
	$app_exit_infos = get_exit_appinfo_fromdb_forcomment();
	foreach ($app_exit_infos as $app_exit)
	{
		$appid = $app_exit['app_id'];
		decodeurlandgetcomment($app_exit,"http://3g.gfan.com/data/index.php?/detail/ajaxcomment/".$appid."/",$appid);
	}
}

function decodeurlandgetcomment($app_exit,$urlheader,$appid)
{
//	$app_exit_infos = get_exit_appinfo_fromdb();
	$app_exit_versions = get_exit_appversion_fromdb();
	$app_exit_comment = get_exit_appcomment_fromdb($appid);
	
	for($i=0;;)
	{
		$apps_url_comment = $urlheader.$i."/";
		@$json_string = file_get_html($apps_url_comment);
//		$json_str = json_decode($json_string);
		$json_str = $json_string;
		$json_str = substr($json_str, 0, -1);
		$json_str = substr($json_str, 1, strlen($json_str));
		$obj = json_decode($json_str);
		
		$appinfoarr = $obj->list;
		
		//本次为空，结束
		if((count($appinfoarr) == 0) || ($appinfoarr == ""))
		{
			break;
		}
		
		//有内容，解析
		$app_info_arr_insertdb_arr = catchcommentdata($appinfoarr);
		if((count($app_info_arr_insertdb_arr) == 0) || ($app_info_arr_insertdb_arr == ""))
		{
			break;
		}
		//写数据库
		foreach ($app_info_arr_insertdb_arr as $app_info_arr_insertdb)
		{
			$app_info_arr_insertdb['app_id'] = $app_exit['id'];
			$app_info_arr_insertdb['app_version_id'] = 0;
			foreach ($app_exit_versions as $app_versions)
			{
				if($app_versions['app_id'] == $app_info_arr_insertdb['app_id'])
				{
					$app_info_arr_insertdb['app_version_id'] = $app_versions['id'];
					break;
				}
			}
			//判断是否需要更新信息库
			$searchcommentid = searchcommentisexit($app_info_arr_insertdb, $app_exit_comment);
			if($searchcommentid == 0)
			{
				update_appcomment_todb($app_info_arr_insertdb,3);
				//_ifnotexit_todb($app_info_arr_insertdb);
				
				//重新获取存在app信息，因为有了更新
//				$app_exit_comment = get_exit_appcomment_fromdb();
			}
			else 
			{
				//存在，则说明之后评论已抓过
//				return ;
			}
		}
		$i++;
	}
}

//排名分类，app大类，app信息
function catchcommentdata($appcommentarr)
{
	$app_info_insertdb_arr = array();
	
	$catchdate_arr = array();
	for($i=1;$i<=31;$i++)
	{
		$catchdate_arr[] = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$i,date("Y")));
	}
	
	foreach ($appcommentarr as $appcomment)
	{
		$app_info_insertdb = array();
		
//		$app_info_insertdb['id'] = $appcomment->id;
		$app_info_insertdb['content'] = addslashes($appcomment->comment);

		$datetime = date('Y-m-d H:i:s',($appcomment->date/1000));
		$app_info_insertdb['date'] = $datetime;
		$app_info_insertdb['author_name'] = addslashes($appcomment->author);
		$app_info_insertdb['author_id'] = $appcomment->comment_id;//此id用来记录评论id
		$app_info_insertdb['type'] = "";
		
		$catchdate = date('Y-m-d',($appcomment->date/1000));
		if(in_array($catchdate,$catchdate_arr))
		{
			$app_info_insertdb_arr[] = $app_info_insertdb;
		}
		
	}
	
	return $app_info_insertdb_arr;
}

//监控信息
function update_appcomment_todb($app_comment,$platform_id)
{
	$link = mysql_connect("localhost","root",DBPAS); 
	$createtime = strtotime(date("Y-m-d H:i:s"));
	
	//$datano = date("Y-m-d",strtotime($app_comment["date"]));
	
	$sql = 'insert into jk_apps_comments_detail_jifeng (app_id,app_version_id,platform_id,author_id,author_name,content,scoretype,time,datetime)
	 values ('.$app_comment['app_id'].','.$app_comment['app_version_id'].','.$platform_id.',"'.$app_comment['author_id'].'","'.$app_comment['author_name'].'","'.$app_comment['content'].'","'.$app_comment['type'].'","'.$app_comment['date'].'","'.$app_comment['date'].'")'; 

//	echo $sql;die();
	$rs = mysql_query($sql, $link);
	
	$filename_success = LOGPATHHEADER.'logs/jifeng_success.log';
	$filename_fail = LOGPATHHEADER.'logs/jifeng_fail.log';
	$filename_db_fail = LOGPATHHEADER.'logs/jifeng_db_fail.log';

	try
	{
		if(!$rs)
		{
			//记录错误，二次抓取用
			$info_str = $app_comment["app_id"].$sql."Valid result!\r\n";
			$fh = fopen($filename_db_fail, "a");
			fwrite($fh, $info_str);
			fclose($fh);
			echo $info_str;
		}
		else
		{
			if(LOGFORSUCCESS)
			{
				$info_str = $app_comment["app_id"]."success!\r\n";
				$filename = $filename_success;
				$fh = fopen($filename, "a");
				fwrite($fh, $info_str);
				fclose($fh);
			}
		}
	}
	catch(Exception $e)
	{
		
	}
}



function get_exit_appcomment_fromdb($appid)
{
	$link = mysql_connect("localhost","root",DBPAS); 
	
	//$sql = 'select id,app_id,app_version_id,author_id,author_name,content,time,datetime from jk_apps_comments_detail_jifeng where IsDeleted=0 '; 
	$sql = 'select a.id as id,a.app_id as app_id,a.app_version_id as app_version_id,a.author_id as author_id,a.author_name as author_name,a.content as content,a.time as time,a.datetime as datetime from jk_apps_comments_detail_jifeng as a,jk_apps_info_jifeng as b where b.id=a.app_id and b.app_id='.$appid.' and a.IsDeleted=0 ';
	$rs = mysql_query($sql, $link);
	
	$app_exit_comment = array();
  	while($row=mysql_fetch_array($rs))        
  	{
  		$app_exit_comment_temp = array();
	  	$app_exit_comment_temp['id'] = $row['id'];
	  	$app_exit_comment_temp['app_id'] = $row['app_id'];
	  	$app_exit_comment_temp['app_version_id'] = $row['app_version_id'];
	  	$app_exit_comment_temp['author_id'] = $row['author_id'];
	  	$app_exit_comment_temp['author_name'] = $row['author_name'];
	  	$app_exit_comment_temp['content'] = $row['content'];
	  	$app_exit_comment_temp['time'] = $row['time'];
	  	$app_exit_comment_temp['datetime'] = $row['datetime'];
	  	$app_exit_comment[] = $app_exit_comment_temp;
  	}
	return $app_exit_comment;
}

function searchcommentisexit($app_comment, $app_exit_comment)
{
	foreach ($app_exit_comment as $app_exit) 
	{
		//if (($app_comment['app_id'] == $app_exit["app_id"]) && ($app_comment['app_version_id'] == $app_exit["app_version_id"]) && ($app_comment['author_name'] == $app_exit["author_name"]) && ($app_comment['content'] == $app_exit["content"]) && ($app_comment['date'] == $app_exit["datetime"])) 
		if ($app_comment['author_id'] == $app_exit["author_id"])
		{
			return $app_exit['id'];
		}
	}
	return 0;
}


function get_exit_appinfo_fromdb_forcomment()
{
	$link = mysql_connect("localhost","root",DBPAS); 
	$createtime = strtotime(date("Y-m-d H:i:s"));
	//select id, app_id, packageName,title from jk_apps_info_jifeng where id not in (select a.id from jk_apps_info_jifeng as a,jk_apps_comments_detail_jifeng as b where b.app_id = a.id and a.IsDeleted=0 ) 
	$sql = 'select id, app_id, packageName,title from jk_apps_info_jifeng where id in (select app_id from jk_apps_score_data_mobile_jifeng_'.date('Ym',time()).' where comments>0 and IsDeleted=0 ) and id >=60001 and id <=90000'; 
	$rs = mysql_query($sql, $link);
	
	$app_exit_info = array();
  	while($row=mysql_fetch_array($rs))        
  	{
  		$app_exit_info_temp = array();
  		$app_exit_info_temp['id'] = $row['id'];
  		$app_exit_info_temp['app_id'] = $row['app_id'];
	  	$app_exit_info_temp['AppPackageName'] = $row['packageName'];
	  	$app_exit_info_temp['AppName'] = $row['title'];
	  	$app_exit_info[] = $app_exit_info_temp;
  	}
	return $app_exit_info;
}




?>